package main.java.com.amanda.pro;

import edu.princeton.cs.algs4.Stack;
import edu.princeton.cs.algs4.StdIn;
import edu.princeton.cs.algs4.StdOut;
import edu.princeton.cs.algs4.Transaction;
import main.java.com.amanda.utils.MinPQ;

import java.util.Scanner;

/**
 * @author amanda
 * @Description 一个优先队列的用例
 */
public class TopM {
    public static void main(String[] args) {
        int M = 5;
        MinPQ<Transaction> pq = new MinPQ<>(M+1);
        String[] a = {"Turing 6/17/1990 644.08", "vonNeumann 3/26/2002 4121.85", "Dijkstra 8/22/2007 2678.40",
                "vonNeumann 1/1/1999 4409.74", "Dijkstra 11/18/1995 837.42", "Hoare 8/18/1992 4381.21",
                "Turing 1/11/2002 66.40", "Thomson 2/27/2000 66.10", "Turing 2/11/1991 2156.86",
                "Hoare 8/12/2003 1025.70", "vonNeumann 10/13/1993 2520.70"};
        for (int i = 0; i < a.length; i++) {
            pq.insert(new Transaction(a[i]));
            if (pq.size() > M)
                pq.delMin();
        }
        Stack<Transaction> stack = new Stack<>();
        while (!pq.isEmpty())
            stack.push(pq.delMin());
        for (Transaction transaction : stack) {
            StdOut.println(transaction);
        }
    }
}
/*
Turing 6/17/1990 644.08
vonNeumann 3/26/2002 4121.85
Dijkstra 8/22/2007 2678.40
vonNeumann 1/1/1999 4409.74
Dijkstra 11/18/1995 837.42
Hoare 8/18/1992 4381.21
Turing 1/11/2002 66.40
Thomson 2/27/2000 66.10
Turing 2/11/1991 2156.86
Hoare 8/12/2003 1025.70
vonNeumann 10/13/1993 2520.70
 */
